package com.oa.system.controller;

import com.joneying.common.web.response.Resp;
import com.oa.system.entity.Permission;
import com.oa.system.entity.Post;
import com.oa.system.entity.User;
import com.oa.system.service.IPermissionService;
import com.oa.system.service.IPostService;
import com.oa.system.service.IUserService;
import com.oa.system.vo.PermissionVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.joneying.common.annotation.CommonController;
import org.springframework.context.annotation.Description;

import java.util.Collections;
import java.util.List;

import org.springframework.web.bind.annotation.RestController;
import com.oa.core.BaseController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author syb123
 * @since 2019-01-29
 */
@RestController
@RequestMapping("/permission")
@Api(description = "权限表模块")
//@ApiIgnore
public class PermissionController extends BaseController {

    private final IPermissionService permissionService;

    @Autowired
    public PermissionController(IPermissionService permissionService) {
        this.permissionService = permissionService;
    }

    @Autowired
    private IUserService userService;

    @GetMapping("/list/tree")
    @CommonController
    @Description("根据岗位ID查询所有权限")
    @ApiOperation(value = "查询所有权限")
    public Resp<PermissionVO> findPermissionListByPostId(){
        User user = userService.selectById(getLoginUserId());
        if(user == null){
            return new Resp().failure("用户不存在");
        }
        String postId = user.getPostId();
        return new Resp().success(permissionService.findPermissionList(postId == null ? "0" : postId));
    }

    @GetMapping("/list")
    @CommonController
    @Description("查询所有权限")
    @ApiOperation(value = "查询所有权限")
    public Resp<PermissionVO> findPermissionList(){
        return new Resp().success(permissionService.findPermissionList(null));
    }

//    /**
//     * 根据Id删除
//     *
//     * @param id id
//     * @return Resp
//     */
//    @DeleteMapping("/{id}")
//    @CommonController
//    @Description("根据id删除")
//    @ApiOperation(value = "根据id删除")
//    public Resp delete(@ApiParam(value = "id", required = true) @PathVariable("id") String id) {
//        if (permissionService.deletePermission(id)) {
//            return new Resp().success();
//        }
//        return new Resp().failure();
//    }
}
